package com.example.meetdroid.listview;



import java.util.List;

import com.example.meetdroid.R;
import com.example.meetdroid.main.User;

import android.app.Activity;
import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.TextView;

public class UserListAdapter extends ArrayAdapter<User> {

	protected static final String LOG_TAG = UserListAdapter.class.getSimpleName();
	
	private List<User> items;
	private int layoutResourceId;
	private Context context;

	public UserListAdapter(Context context, int layoutResourceId, List<User> items) {
		super(context, layoutResourceId, items);
		this.layoutResourceId = layoutResourceId;
		this.context = context;
		this.items = items;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		UserHolder holder = null;

		LayoutInflater inflater = ((Activity) context).getLayoutInflater();
		row = inflater.inflate(layoutResourceId, parent, false);

		holder = new UserHolder();
		holder.cUser = items.get(position);
		holder.cBtnSendMessage = (ImageButton)row.findViewById(R.id.lvrowBtnSendMessage);
		holder.cBtnSendMessage.setTag(holder.cUser);
		holder.cTxtViewName = (TextView)row.findViewById(R.id.lvrowTxtViewFriendName);
		row.setTag(holder);
		setupItem(holder);
		return row;
	}

	private void setupItem(UserHolder holder) {
		holder.cTxtViewName.setText(holder.cUser.getName());
	}

	public static class UserHolder {
		User cUser;
		TextView cTxtViewName;
		ImageButton cBtnSendMessage;
	}

}
